package average;

import java.util.Arrays;

public class Solution {
    public double average(int[] salary) {
        // 思路 先来个暴力
//        Arrays.sort(salary);
//        int sum = 0;
//        for (int i = 1; i <salary.length-1 ; i++) {
//            sum+=salary[i];
//        }
//        return (sum*1.0)/(salary.length-2);

        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        int sum = Arrays.stream(salary).sum();
        for (int num: salary) {
            if(num>max){
                // 如果最大值是num，那么就把num改成最大值
                max = num;
            }
            if(min>num){
                min = num;
            }
        }
        return (sum*1.0-min-max)/(salary.length-2);
    }
}
